package lab03.test8;

import java.io.*;

public class Test8 {
    public static void main(String[] args) {
        String path1="D:\\1.txt";
        String path2="D:\\2.txt";
        String path3="D:\\3.txt";
        FileInputStream fileInputStream=null;
        FileOutputStream fileOutputStream=null;
        FileInputStream fileInputStream1=null;
        try {
            fileInputStream=new FileInputStream(path1);
            fileInputStream1= new FileInputStream(path2);
            fileOutputStream=new FileOutputStream(path3);
            int a=0;
            int b=0;
            int c=0;
            while((c=((a=fileInputStream.read())>(b=fileInputStream1.read()))?a:b)!=-1){
                if (a!=-1){
                   fileOutputStream.write(a);
                }
                if (b!=-1){
                 fileOutputStream.write(b);
               }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                fileInputStream1.close();
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
